package com.burgeon.backend.Rest.Tags;
/**
 * 添加标签
 */


import com.burgeon.backend.Rest.base.RESTBase;
import com.burgeon.backend.entity.User;
import org.json.JSONArray;
import org.springframework.util.MultiValueMap;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

public class AddTagsBos extends RESTBase {

    private String ip;
    private String account;
    private String password;

    public AddTagsBos(String ip, String account, String password) {
        this.ip = ip;
        this.account = account;
        this.password = password;
    }

    /**
     * 发送并接收字符创
     */

    public void getData(String tid, String name) throws Exception {
        String url = "http://" + ip + "/servlets/binserv/Rest";

        String str = RESULT(Data(tid, name), url);
        System.err.println(str);
        String code = new JSONArray(str).getJSONObject(0).getString("code");

        if (!"0".equals(code)) {
            throw new Exception("注册失败");
        }

    }

    private MultiValueMap Data(String tid, String name) {

        HashMap params = new HashMap();
        HashMap masterobj = new HashMap(); //头表记录对象
        masterobj.put("table", "C_VIPATTRIBDEF");
        masterobj.put("id", tid);


        HashMap detailobjs = new HashMap(); //明细表记录对象
        ArrayList list = new ArrayList();
        list.add(944);

        detailobjs.put("reftables", list);
//****************************************************************************
        ArrayList refobjs = new ArrayList();
        HashMap ref1 = new HashMap();
        ref1.put("table", "C_VIPATTRIBVALUE");
        List addList1 = new ArrayList();
        HashMap map1 = new HashMap();
        map1.put("id", "-1");

        map1.put("NAME", name);

        addList1.add(map1);

        ref1.put("addList", String.valueOf(addList1));

        refobjs.add(ref1);

        detailobjs.put("refobjs", refobjs);
        params.put("masterobj", masterobj);
        params.put("detailobjs", detailobjs);
        return DATA("ProcessOrder", params, account, password);
    }

    public static void main(String[] args) {
        AddTagsBos g = new AddTagsBos("39.100.45.8:55322", "nea@burgeon.com.cn", "123");
        try {
            g.getData("3", "属性分类1");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
